<template>
  <div :class="['app', theme]">
    <NavBar :theme="theme" @toggle-theme="toggleTheme" />
    <router-view />
  </div>
</template>

<script>
import NavBar from './components/NavBar.vue'
import { mapState, mapActions } from 'vuex'
export default {
  name: 'App',
  components: { NavBar },
  computed: {
    ...mapState({
      theme: state => state.settings.theme
    })
  },
  methods: {
    ...mapActions('settings', ['setTheme']),
    toggleTheme() {
      const newTheme = this.theme === 'dark' ? 'light' : 'dark'
      this.setTheme(newTheme)
    }
  },
  watch: {
    theme(val) {
      document.documentElement.setAttribute('data-theme', val)
    }
  },
  mounted() {
    document.documentElement.setAttribute('data-theme', this.theme)
  }
}
</script>

<style>
:root {
  --primary-color: #4a90e2;
  --secondary-color: #2c3e50;
  --background-color: #ffffff;
  --text-color: #2c3e50;
  --border-color: #e0e0e0;
  --success-color: #28a745;
  --error-color: #dc3545;
  --hover-color: #f8f9fa;
}

[data-theme="dark"] {
  --primary-color: #64b5f6;
  --secondary-color: #e0e0e0;
  --background-color: #1a1a1a;
  --text-color: #e0e0e0;
  --border-color: #333333;
  --hover-color: #2d2d2d;
}

.app {
  font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: var(--text-color);
  background-color: var(--background-color);
  min-height: 100vh;
  transition: all 0.3s ease;
}

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  background-color: var(--primary-color);
  color: white;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.nav-logo-brand {
  display: flex;
  align-items: center;
}

.logo-img {
  height: 40px;
  margin-right: 16px;
  vertical-align: middle;
}

.nav-brand {
  font-size: 1.5rem;
  font-weight: bold;
  margin-right: 2rem;
}

.theme-toggle {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0.5rem;
  border-radius: 50%;
  transition: background-color 0.3s;
}

.theme-toggle:hover {
  background-color: rgba(255,255,255,0.1);
}

.practice-type-bar {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin: 2rem 0 1rem 0;
}

.type-btn {
  background: var(--hover-color);
  color: var(--primary-color);
  border: 2px solid var(--primary-color);
  border-radius: 2rem;
  padding: 0.5rem 2rem;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s;
}

.type-btn.active, .type-btn:hover {
  background: var(--primary-color);
  color: #fff;
}

.typing-container {
  max-width: 800px;
  margin: 0 auto;
  padding: 2rem;
}

.header {
  text-align: center;
  margin-bottom: 2rem;
}

h1 {
  color: var(--primary-color);
  margin-bottom: 0.5rem;
  font-size: 2.5rem;
}

.subtitle {
  color: var(--secondary-color);
  font-size: 1.1rem;
  opacity: 0.8;
}

.progress-container {
  background-color: var(--border-color);
  border-radius: 10px;
  height: 8px;
  margin: 1rem 0;
  position: relative;
  overflow: hidden;
}

.progress-bar {
  background-color: var(--primary-color);
  height: 100%;
  transition: width 0.3s ease;
}

.progress-text {
  position: absolute;
  right: 0;
  top: -20px;
  font-size: 0.9rem;
  color: var(--secondary-color);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin: 2rem 0;
}

.stat-item {
  background-color: var(--hover-color);
  padding: 1rem;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: transform 0.3s;
}

.stat-item:hover {
  transform: translateY(-2px);
}

.stat-icon {
  font-size: 1.5rem;
}

.stat-content {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.9rem;
  opacity: 0.8;
}

.stat-value {
  font-size: 1.2rem;
  font-weight: bold;
  color: var(--primary-color);
}

.text-display {
  font-size: 1.5rem;
  line-height: 1.8;
  margin: 2rem 0;
  padding: 2rem;
  background-color: var(--hover-color);
  border-radius: 10px;
  min-height: 150px;
  text-align: left;
}

.correct {
  color: var(--success-color);
}

.incorrect {
  color: var(--error-color);
  text-decoration: underline;
}

.current {
  background-color: var(--primary-color);
  color: white;
  border-radius: 2px;
}

.input-container {
  margin: 2rem 0;
}

.typing-input {
  width: 100%;
  height: 120px;
  padding: 1rem;
  font-size: 1.2rem;
  border: 2px solid var(--border-color);
  border-radius: 10px;
  resize: none;
  background-color: var(--hover-color);
  color: var(--text-color);
  transition: border-color 0.3s;
}

.typing-input:focus {
  outline: none;
  border-color: var(--primary-color);
}

.controls {
  display: flex;
  justify-content: center;
  margin: 2rem 0;
}

.reset-btn {
  background-color: var(--primary-color);
  color: white;
  border: none;
  padding: 1rem 2rem;
  font-size: 1.1rem;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.reset-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.btn-icon {
  font-size: 1.2rem;
}

.article-info {
  text-align: center;
  margin-top: 2rem;
  color: var(--secondary-color);
  opacity: 0.8;
}

@media (max-width: 768px) {
  .typing-container {
    padding: 1rem;
  }

  .stats {
    grid-template-columns: 1fr;
  }

  .text-display {
    font-size: 1.2rem;
    padding: 1rem;
  }
}

.nav-menu {
  display: flex;
  gap: 2rem;
  flex: 1;
  justify-content: center;
}
.nav-link {
  color: white;
  text-decoration: none;
  font-size: 1.1rem;
  padding: 0.5rem 1rem;
  border-radius: 5px;
  transition: background 0.2s;
}
.nav-link:hover, .active-link {
  background: rgba(255,255,255,0.15);
}

.user-info {
  margin-left: 1rem;
  color: #fff;
}
.login-btn, .logout-btn {
  background: transparent;
  border: 1px solid #fff;
  color: #fff;
  border-radius: 5px;
  padding: 0.3rem 1rem;
  margin-left: 0.5rem;
  cursor: pointer;
  transition: background 0.2s;
}
.login-btn:hover, .logout-btn:hover {
  background: rgba(255,255,255,0.15);
}
</style>
